Skip to content

Conversation

@FrozenPandaz
Copy link
Collaborator

@FrozenPandaz FrozenPandaz commented Oct 29, 2025

Summary

This PR adds support for additional project directories throughout the Nx workspace, enabling workspaces to manage projects across multiple root directories.

This can be enabled in nx.json by adding:

{
  "additionalProjectDirectories": [
    "../packages"
  ]
}

Projects in pnpm-workspaces.yaml in those external directories should then get picked up.

Changes

  • feat(core): add support for additional project directories - Initial implementation of additional project root support
  • feat(core): update additional project directories handling - Refine workspace file handling and path utilities to properly support additional project directories across native and TypeScript layers

Related Issue(s)

These changes enable proper handling of additional project roots in Nx workspaces.

#30622

@FrozenPandaz FrozenPandaz requested review from a team and leosvelperez as code owners October 29, 2025 20:41
@vercel
Copy link

vercel bot commented Oct 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Oct 30, 2025 10:47pm

@netlify
Copy link

netlify bot commented Oct 29, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit a25d58c
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6903ea2223972c00089d37ef
😎 Deploy Preview https://deploy-preview-33300--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Oct 29, 2025

View your CI Pipeline Execution ↗ for commit a25d58c

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 35m 10s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 1m 38s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 11s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 3s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-30 23:25:52 UTC

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

Add native workspace support for additional project roots alongside the main workspace root. This enables workspaces to define multiple project directories for better organization and flexibility.

Changes include:
- New Rust module for handling additional project directories
- Updated workspace context to support multiple project roots
- Extended project graph utilities to recognize additional directories
- Updated package.json plugin creation with new API
nx-cloud[bot]

This comment was marked as outdated.

Copy link
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud is proposing a fix for your failed CI:

These changes fix test failures caused by undefined configuration file paths being passed to the package.json plugin's splitConfigFiles function. We added proper null/undefined filtering when concatenating additional project configuration files, and updated function signatures throughout the codebase to properly handle the new additionalProjectDirectories parameter, ensuring that workspace context and file retrieval operations work correctly with this new feature.

We verified this fix by re-running nx:format-native.

Suggested Fix changes
diff --git a/packages/nx/src/native/tasks/hashers/hash_project_files.rs b/packages/nx/src/native/tasks/hashers/hash_project_files.rs
index 972ede159c..35fa4667fd 100644
--- a/packages/nx/src/native/tasks/hashers/hash_project_files.rs
+++ b/packages/nx/src/native/tasks/hashers/hash_project_files.rs
@@ -177,7 +177,9 @@ mod tests {
                 file_data4.clone(),
             ],
         );
-        let hash_result = hash_project_files(&workspace_root, proj_name, proj_root, file_sets, &file_map).unwrap();
+        let hash_result =
+            hash_project_files(&workspace_root, proj_name, proj_root, file_sets, &file_map)
+                .unwrap();
         assert_eq!(
             hash_result,
             hash(
@@ -228,7 +230,9 @@ mod tests {
                 file_data4.clone(),
             ],
         );
-        let hash_result = hash_project_files(&workspace_root, proj_name, proj_root, file_sets, &file_map).unwrap();
+        let hash_result =
+            hash_project_files(&workspace_root, proj_name, proj_root, file_sets, &file_map)
+                .unwrap();
         assert_eq!(
             hash_result,
             hash(
diff --git a/packages/nx/src/native/tests/workspace_files.spec.ts b/packages/nx/src/native/tests/workspace_files.spec.ts
index 736cf0e3c2..1a09c98973 100644
--- a/packages/nx/src/native/tests/workspace_files.spec.ts
+++ b/packages/nx/src/native/tests/workspace_files.spec.ts
@@ -54,7 +54,7 @@ describe('Workspace Context', () => {
       fs.tempDir,
       cacheDirectoryForWorkspace(fs.tempDir)
     );
-    let { projectFileMap, globalFiles } = await context.getWorkspaceFiles({
+    let { projectFileMap, globalFiles } = await context.getWorkspaceFiles([], {
       'libs/project1': 'project1',
       'libs/project2': 'project2',
       'libs/project3': 'project3',
@@ -156,9 +156,12 @@ describe('Workspace Context', () => {
       cacheDirectoryForWorkspace(fs.tempDir)
     );
 
-    const { globalFiles, projectFileMap } = await context.getWorkspaceFiles({
-      '.': 'repo-name',
-    });
+    const { globalFiles, projectFileMap } = await context.getWorkspaceFiles(
+      [],
+      {
+        '.': 'repo-name',
+      }
+    );
 
     expect(globalFiles).toEqual([]);
     expect(projectFileMap['repo-name']).toMatchInlineSnapshot(`
diff --git a/packages/nx/src/plugins/package-json/create-nodes.ts b/packages/nx/src/plugins/package-json/create-nodes.ts
index 25c8e71dc1..a5e85df398 100644
--- a/packages/nx/src/plugins/package-json/create-nodes.ts
+++ b/packages/nx/src/plugins/package-json/create-nodes.ts
@@ -36,7 +36,7 @@ export const createNodesV2: CreateNodesV2 = [
   ),
   (configFiles, _, context) => {
     const { packageJsons, projectJsonRoots } = splitConfigFiles(
-      configFiles.concat(context.additionalProjectConfigurationFiles)
+      configFiles.concat(context.additionalProjectConfigurationFiles ?? [])
     );
 
     const readJson = (f) => readJsonFile(join(context.workspaceRoot, f));
diff --git a/packages/nx/src/project-graph/utils/retrieve-workspace-files.spec.ts b/packages/nx/src/project-graph/utils/retrieve-workspace-files.spec.ts
index ade2bf876f..ae1682103e 100644
--- a/packages/nx/src/project-graph/utils/retrieve-workspace-files.spec.ts
+++ b/packages/nx/src/project-graph/utils/retrieve-workspace-files.spec.ts
@@ -37,17 +37,21 @@ describe('retrieve-workspace-files', () => {
         })
       );
 
-      const configPaths = await retrieveProjectConfigurationPaths(fs.tempDir, [
-        {
-          name: 'test',
-          createNodes: [
-            '{project.json,**/project.json}',
-            async () => {
-              return [];
-            },
-          ],
-        },
-      ]);
+      const configPaths = await retrieveProjectConfigurationPaths(
+        fs.tempDir,
+        [],
+        [
+          {
+            name: 'test',
+            createNodes: [
+              '{project.json,**/project.json}',
+              async () => {
+                return [];
+              },
+            ],
+          },
+        ]
+      );
 
       expect(configPaths).not.toContain('not-projects/project.json');
       expect(configPaths).toContain('projects/project.json');

🤖 The fix was applied automatically after verification.

Revert fix via Nx Cloud  View interactive diff ↗


🎓 To learn more about Self Healing CI, please visit nx.dev

Refine workspace file handling and path utilities to properly support
additional project directories throughout the native and TypeScript layers.
@github-actions
Copy link
Contributor

🐳 We have a release for that!

This PR has a release associated with it. You can try it out using this command:

npx [email protected] my-workspace

Or just copy this version and use it in your own command:

0.0.0-pr-33300-a25d58c
Release details 📑
Published version 0.0.0-pr-33300-a25d58c
Triggered by @FrozenPandaz
Branch add-proj-roots
Commit a25d58c
Workflow run 18974466801

To request a new release for this pull request, mention someone from the Nx team or the @nrwl/nx-pipelines-reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants